import pandas as pd
from sklearn.preprocessing import LabelBinarizer

df = pd.read_csv("D:\数据挖掘\数据预处理-两次实验\数据预处理-实验2\\titanic.csv", usecols=['Embarked'])
# 创建df文件的副本
df1 = df.copy()

# 创建一个LabelBinarizer对象
label_binarizer = LabelBinarizer()

# 拟合floor列到LabelBinarizer
label_binarizer_output = label_binarizer.fit_transform(df1['Embarked'].astype(str))    #astype(str)左右数据类型不一致，不转化会报错

# 使用DataFrame
result_df = pd.DataFrame(label_binarizer_output,
                         columns=label_binarizer.classes_)

# result_df=LabelBinarizer().fit_transform(df['floor'])
print("属性Embarked二值化:\n",result_df.to_string())